home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-09-06 | 7.9 KB | 393 lines | [TEXT/CWIE] |
- // Buttons.cp
-
- #include <Types.h>
- #include <Quickdraw.h>
- #include <Controls.h>
- #include <Dialogs.h>
- #include <Events.h>
- #include <Lists.h>
- #include <Menus.h>
- #include <Resources.h>
- #include <Sound.h>
- #include <TextEdit.h>
- #include <ToolUtils.h>
- #include <Appearance.h>
-
- #include "Globals.h"
- #include "ResourceDefs.h"
- #include "DoScrap.h"
- #include "Miscellany.h"
- #include "Scrolling.h"
- #include "ControlUtils.h"
- #include "DDocData.h"
- #include "GadgetsEngine.h"
- #include "GadgetsDoc.h"
-
- #include "Buttons.h"
-
-
- //----------
- void Buttons::Create (
- AMDoc* inDoc,
- DDocData* inData)
- {
- Buttons* winObj = new Buttons;
-
- if (winObj != nil) {
- winObj->Open (inDoc);
- winObj->ConnectToData (inData);
- }
- }
-
- //----------
- Buttons::Buttons ()
- {
- mData = nil;
- }
-
- //----------
- Buttons::~Buttons ()
- {
- }
-
- //----------
- GadgetsEngine* Buttons::GetEngine ()
- {
- return (GadgetsEngine*) mDoc->mEngine;
- }
-
- //----------
- void Buttons::Open (
- AMDoc* inDoc)
- {
- WindowPtr window;
- Handle wftb;
-
- mDoc = inDoc;
-
- window = GetNewCWindow (WIND_Buttons, nil, (WindowPtr) -1L);
- if (mDoc->mEngine->GetFilename () [0] != 0) {
- SetWTitle (window, mDoc->mEngine->GetFilename ());
- }
- mWindow = window;
- ((GadgetsDoc*)mDoc)->mButtonsPtr = window;
-
- SetWindowKind (window, 'AM');
- SetWRefCon (window, (long) this);
- SetPort (window);
- SetInfo (window);
-
- wftb = ::GetResource ('Wftb', WIND_Buttons);
-
- CreateRootControl (window, &mRootControl);
-
- vScroll = nil;
- hScroll = nil;
-
-
- mStandardHandle = ::GetNewControl (CNTL_Standard, window);
- SetWindowItemFont (mStandardHandle, wftb, 1);
- SetDefaultState (mStandardHandle, true);
-
- mRightIconHandle = ::GetNewControl (CNTL_RightIcon, window);
- SetWindowItemFont (mRightIconHandle, wftb, 2);
-
- mBevelHandle = ::GetNewControl (CNTL_Bevel, window);
- SetWindowItemFont (mBevelHandle, wftb, 3);
- SetBevelButtonTextPlacement (mBevelHandle, kControlBevelButtonPlaceToRightOfGraphic);
- SetBevelButtonTextAlignment (mBevelHandle, kControlBevelButtonAlignTextFlushLeft, 0);
- SetBevelButtonGraphicAlignment (mBevelHandle, kControlBevelButtonAlignLeft, 0, 0);
-
- mXxHandle = ::GetNewControl (CNTL_Xx, window);
- SetWindowItemFont (mXxHandle, wftb, 4);
-
- mCapTriangleLabel = GetNewControl (CNTL_CapTriangle, window);
- SetWindowItemFont (mCapTriangleLabel, wftb, 5);
- SetControlFromTEXT (mCapTriangleLabel, TEXT_CapTriangle);
-
- mLightHandle = ::GetNewControl (CNTL_Light, window);
- SetWindowItemFont (mLightHandle, wftb, 6);
-
- mLeftRightHandle = ::GetNewControl (CNTL_LeftRight, window);
- SetWindowItemFont (mLeftRightHandle, wftb, 7);
-
- mRadiosBoxHandle = GetNewControl (CNTL_RadiosBox, window);
- SetWindowItemFont (mRadiosBoxHandle, wftb, 8);
- mRadiosGroupHandle = GetNewControl (CNTL_RadiosGroup, window);
- EmbedControl (mRadiosGroupHandle, mRadiosBoxHandle);
-
- mRadioButtonHandle = ::GetNewControl (CNTL_RadioButton, window);
- EmbedControl (mRadioButtonHandle, mRadiosGroupHandle);
- SetWindowItemFont (mRadioButtonHandle, wftb, 10);
- SetBevelButtonGraphicAlignment (mRadioButtonHandle, kControlBevelButtonAlignCenter, 0, 0);
-
- mRadioButton2Handle = ::GetNewControl (CNTL_RadioButton2, window);
- EmbedControl (mRadioButton2Handle, mRadiosGroupHandle);
- SetWindowItemFont (mRadioButton2Handle, wftb, 11);
- SetBevelButtonGraphicAlignment (mRadioButton2Handle, kControlBevelButtonAlignCenter, 0, 0);
-
- mInvisibleHandle = ::GetNewControl (CNTL_Invisible, window);
- SetWindowItemFont (mInvisibleHandle, wftb, 12);
-
- mCapInvisibleLabel = GetNewControl (CNTL_CapInvisible, window);
- SetWindowItemFont (mCapInvisibleLabel, wftb, 13);
- SetControlFromTEXT (mCapInvisibleLabel, TEXT_CapInvisible);
-
- AdvanceKeyboardFocus (window);
-
- ShowWindow (window);
- }
-
- //----------
- void Buttons::Close ()
- {
- mData->RemoveResponder (this);
-
- ((GadgetsDoc*)mDoc)->mButtonsPtr = nil;
- SetInfo (nil);
- HideWindow (mWindow);
- DisposeWindow (mWindow);
-
- delete this;
- }
-
- //----------
- void Buttons::ConnectToData (
- DDocData* inData)
- {
- mData = inData;
- mData->AddResponder (this);
-
- SetControlValue (mXxHandle, mData->GetTriangle ());
- SetControlValue (mLeftRightHandle, mData->GetLeftRight ());
- SetControlValue (mRadiosGroupHandle, mData->GetRadios ());
- }
-
- //----------
- void Buttons::DataChanged (
- long inDataID)
- {
- if (inDataID == idTriangle) {
- SetControlValue (mXxHandle, mData->GetTriangle ());
- }
- if (inDataID == idLeftRight) {
- SetControlValue (mLeftRightHandle, mData->GetLeftRight ());
- }
- if (inDataID == idRadios) {
- SetControlValue (mRadiosGroupHandle, mData->GetRadios ());
- }
- }
-
- //----------
- void Buttons::Control (
- ControlHandle whichControl,
- short whichPart,
- Point where)
- {
- Rect bounds;
- short newValue;
-
- ExitCurField ();
-
- if (whichControl == mStandardHandle) {
- if (TrackClick (mStandardHandle, where)) {
- }
- }
- if (whichControl == mRightIconHandle) {
- if (TrackClick (mRightIconHandle, where)) {
- }
- }
- if (whichControl == mBevelHandle) {
- if (TrackClick (mBevelHandle, where)) {
- }
- }
- if (whichControl == mXxHandle) {
- if (TrackCheckbox (mXxHandle, where)) {
- mData->SetTriangle (GetControlValue (mXxHandle) != 0);
- }
- }
- if (whichControl == mLightHandle) {
- if (TrackClick (mLightHandle, where)) {
- }
- }
- if (whichControl == mLeftRightHandle) {
- if (TrackCheckbox (mLeftRightHandle, where)) {
- mData->SetLeftRight (GetControlValue (mLeftRightHandle) != 0);
- }
- }
- if (whichControl == mRadiosGroupHandle) {
- if (TrackClick (whichControl, where) != 0) {
- mData->SetRadios (GetControlValue (mRadiosGroupHandle));
- }
- }
- if (whichControl == mInvisibleHandle) {
- if (TrackClick (mInvisibleHandle, where)) {
- }
- }
- }
-
- //----------
- void Buttons::MouseIn (
- Point where,
- short modifiers)
- {
- Rect bounds;
-
- }
-
- //----------
- void Buttons::ExitCurField ()
- {
- ControlHandle focus;
-
- GetKeyboardFocus (mWindow, &focus);
-
- if (focus == nil) {
- // nothing to exit
-
- }
- }
-
- //----------
- void Buttons::TypeIn (
- char ch)
- {
- ControlHandle focus;
- SInt16 keyCode;
-
- GetKeyboardFocus (mWindow, &focus);
-
- if ((ch == charEnter)
- || (ch == charReturn)) {
- ExitCurField ();
- SimulateClick (mStandardHandle);
- } else if (ch == charEsc) {
- } else if (ch == charTab) {
- DoTab ((curEvent.modifiers & optionKey) != 0);
- } else if (focus != nil) {
- keyCode = (SInt16)(curEvent.message & keyCodeMask);
- HandleControlKey (focus, keyCode, ch, (SInt16)curEvent.modifiers);
- mDoc->mEngine->SetDirty ();
- } else {
- SysBeep (1);
- }
- }
-
- //----------
- void Buttons::Resize ()
- {
- /* application-specific code to resize items in window */
- }
-
- //----------
- void Buttons::Scroll (
- short newValue,
- short oldValue)
- {
- /* application-specific code to scroll window */
- if (gWhichScroll == vScroll) {
- } else { // horizontal
- }
- }
-
- //----------
- void Buttons::DoUndo ()
- {
- } // DoUndo
-
- //----------
- void Buttons::DoCut ()
- {
- TEHandle curTE = GetCurTE ();
-
- if (curTE != nil) {
- TECut (curTE);
- mDoc->mEngine->SetDirty ();
- scrapDirty = true;
- }
- } // DoCut
-
- //----------
- void Buttons::DoCopy ()
- {
- TEHandle curTE = GetCurTE ();
-
- if (curTE != nil) {
- TECopy (curTE);
- scrapDirty = true;
- }
- } // DoCopy
-
- //----------
- void Buttons::DoPaste ()
- {
- TEHandle curTE = GetCurTE ();
-
- if (curTE != nil) {
- TEPaste (curTE);
- mDoc->mEngine->SetDirty ();
- }
- } // DoPaste
-
- //----------
- void Buttons::DoClear ()
- {
- TEHandle curTE = GetCurTE ();
-
- if (curTE != nil) {
- TEDelete (curTE);
- mDoc->mEngine->SetDirty ();
- }
- } // DoClear
-
- //----------
- void Buttons::DoSelectAll ()
- {
- TEHandle curTE = GetCurTE ();
-
- if (curTE != nil) {
- TESetSelect (0, 32767, curTE);
- }
- } // DoSelectAll
-
- //----------
- void Buttons::DoShowClipboard ()
- {
- } // DoShowClipboard
-
- //----------
- Boolean Buttons::DoCommand (
- long inCommand)
- {
- Boolean result = true;
-
- switch (inCommand) {
- case cmdUndo:
- DoUndo ();
- break;
- case cmdCut:
- DoCut ();
- break;
- case cmdCopy:
- DoCopy ();
- break;
- case cmdPaste:
- DoPaste ();
- break;
- case cmdClear:
- DoClear ();
- break;
- case cmdSelectAll:
- DoSelectAll ();
- break;
- case cmdShowClipboard:
- DoShowClipboard ();
- break;
-
- default:
- result = false;
- } // switch
-
- return result;
- }
-